//
//  MDBaseNetTool.swift
//  麦兜直播
//
//  Created by Apple on 16/10/21.
//  Copyright © 2016年 yeqingyu. All rights reserved.
//

import UIKit

class MDBaseNetTool {
    // MARK:- 创建房间组
    var baseRoomGroup:[MDHomeGroup] = [MDHomeGroup]()
    
}


extension MDBaseNetTool{

    // MARK:- 获取热门数据
    func requestRoomData(isGroup:Bool,urlString:String,parameters:[String:Any]? = nil,result:@escaping()->()) {
        // 1.定义参数
        
        NetWorkTool.requestNetData(urlString:urlString, method: .get, parameters:parameters) { (response) in
            print(response)
            guard let responseDic = response as? [String:NSObject] else {return}
            guard let responseData = responseDic["data"] as? [[String:Any]] else {return}
            
            if isGroup{//组数据
                for dic in responseData{
                    let homeGroup = MDHomeGroup(dic: dic)
                    self.baseRoomGroup.append(homeGroup)
                    
                }
            }else{//非组数据

                let homeGroup = MDHomeGroup()
                
                for dic in responseData{
                    homeGroup.rooms.append(MDRoom(dic: dic as! [String : NSObject]))
                }
                self.baseRoomGroup.append(homeGroup)
            }
            result()
        }
        
    }

}
